package com.agileboot.attendance.domain.project.model;

import com.agileboot.attendance.domain.project.entity.AttProjectEntity;
import com.agileboot.attendance.domain.project.db.service.AttProjectService;
import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 项目模型工厂类
 * 
 * @author ruoyi
 */
@Component
@RequiredArgsConstructor
public class ProjectModelFactory {

    private final AttProjectService projectService;

    /**
     * 创建空白项目模型
     *
     * @return 项目模型
     */
    public ProjectModel create() {
        return new ProjectModel();
    }

    /**
     * 根据ID加载项目模型
     *
     * @param projectId 项目ID
     * @return 项目模型
     */
    public ProjectModel loadById(Long projectId) {
        AttProjectEntity projectEntity = projectService.getById(projectId);
        if (projectEntity == null) {
            throw new ApiException(ErrorCode.Business.PROJECT_OBJECT_NOT_FOUND, projectId);
        }
        return ProjectModel.fromEntity(projectEntity);
    }
} 